package at.fhj.itm11.forum.service.converter;

import java.util.ArrayList;
import java.util.List;

import at.fhj.itm11.forum.model.Post;
import at.fhj.itm11.forum.model.Rating;
import at.fhj.itm11.forum.model.User;
import at.fhj.itm11.forum.service.dtos.PostDTO;
import at.fhj.itm11.forum.service.dtos.RatingDTO;
import at.fhj.itm11.forum.service.dtos.UserDTO;

public class RatingDTOConverter implements DTOConverter<RatingDTO, Rating> {
	private DTOConverter<PostDTO, Post> postDtoConverter = new PostDTOConverter();
	private DTOConverter<UserDTO, User> userDtoConverter = new UserDTOConverter();


	@Override
	public RatingDTO convertToDto(Rating ratingEntity) {
		RatingDTO dto = new RatingDTO();
		dto.setPost(postDtoConverter.convertToDto(ratingEntity.getPost()));
		dto.setUser(userDtoConverter.convertToDto(ratingEntity.getUser()));
		dto.setPositiveRating(ratingEntity.isPositiveRating());
		
		return dto;
	}

	@Override
	public List<RatingDTO> convertToDto(List<Rating> ratingEntities) {
		List<RatingDTO> ratingDtoList = new ArrayList<RatingDTO>();
		
		for(Rating r : ratingEntities) {
			ratingDtoList.add(convertToDto(r));
		}
		
		return ratingDtoList;
	}

	@Override
	public Rating convertToEntity(RatingDTO ratingDto) {
    	Rating r = new Rating();
    	r.setUser(userDtoConverter.convertToEntity(ratingDto.getUser()));
    	r.setPost(postDtoConverter.convertToEntity(ratingDto.getPost()));
    	r.setPositiveRating(ratingDto.isPositiveRating());
		r.setPositiveRating(ratingDto.isPositiveRating());
    	
    	return r;
	}
}
